package com.xsh.gls.service.impl;

import com.xsh.gls.mapper.OrderMapper;
import com.xsh.gls.pojo.Order;
import com.xsh.gls.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

/**
 * @author shkstart
 * @date 2019/1/21 - 16:03
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<Order> selectByPrimaryKey(String orderNumber) throws SQLException {

        return orderMapper.selectByPrimaryKey(orderNumber);
    }

    @Override
    public List<Order> selectByNo(String orderNo,Integer salId) {
        return orderMapper.selectByNo(orderNo,salId);
    }

    @Override
    public Order selectByN(Integer id) {
        return orderMapper.selectByN(id);
    }

    @Override
    public List<Order> selectByOrNo(String orderNo) {
        return orderMapper.selectByOrNo(orderNo);
    }



    @Override
    public List<Order> getByAll(Integer spelno, String orderNumber, String reqNo, Integer sono) {
        return null;
    }

    @Override
    public List<Order> selectByOrderNo(String orderNo) {

        return orderMapper.selectByOrderNo(orderNo);
    }

    @Override
    public int insertSelective(Order record) throws SQLException {
        record.getCountry();
        record.getAddress();
       int count=orderMapper.insertSelective(record);
        return count;
    }

    @Override
    public List<Order> getByAll(Integer spelno, String orderNumber, String reqNo, Integer sono,Integer shippingType) {
        return orderMapper.getByAll(spelno, orderNumber, reqNo, sono,shippingType);
    }

    @Override
    public Order getByOrderNo(String orderNumber) {
        return orderMapper.getByOrderNo(orderNumber);
    }

    @Override
    public boolean updateByPrimaryKeySelective(Order order) {
        boolean flag = false;
        if (orderMapper.updateByPrimaryKeySelective(order)>0){
            flag = true;
        }
        return flag;
    }

    @Override
    public List<Order> orderSelectByOwn(String orderNumber, int CusId) throws SQLException {
        return orderMapper.orderSelectByOwn(orderNumber,CusId);
    }

    @Override
    public List<Order> orderCenter(Order order) {
        return orderMapper.orderCenter(order);
    }

    @Override
    public boolean updateDeclareImgById(Order order) throws Exception {
        if(orderMapper.updateDeclareImgById(order)==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateInsureImgById(Order order) throws Exception {
        if(orderMapper.updateInsureImgById(order)==1){
            return true;
        }
        return false;
    }

    @Override
    public Order queryOrderById(Integer id) throws Exception {
        return orderMapper.queryOrderById(id);
    }

    @Override
    public boolean finshUpdate(Order order) throws Exception {
        if(orderMapper.finshUpdate(order)==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean forfinshUpdate(String[] checkIDs) throws Exception {
        Order order=new Order();
        boolean id=false;
        for (String orderNum:checkIDs) {
            order.setOrderNumber(orderNum);
            order.setFinshtime(new Date());
            if(orderMapper.finshUpdate(order)==1){
                id= true;
            }else{
                id= false;
            }
        }
        return id;
    }

    @Override
    public List<Order> queryOrderByEare(Order order) throws Exception {
        return orderMapper.queryOrderByEare(order);
    }

    @Override
    public Order selectByPay(String id) throws Exception {
        return orderMapper.selectByPay(id);
    }

    @Override
    public boolean updateJiedan(Order order) throws Exception {
        if (orderMapper.updateJiedan(order)==1){
            return true;
        }

        return false;
    }

    @Override
    public boolean updateAllJiedan(String[] orderNumber,Integer salemanid) throws Exception {
        boolean flag = false;
        for (String aa:orderNumber) {
            Order order=orderMapper.getByOrderNo(aa);
            order.setSalesmanid(salemanid);
            order.setOrdertime(new Date());
            if (orderMapper.updateJiedan(order)==1){
                flag = true;
            }else {
                flag = false;
            }
        }

        return flag;
    }

    @Override
    public boolean updatepay(String orderNumber) throws Exception {
        if(orderMapper.updatepay(orderNumber)==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean getByLWOrderNo(String[] orderNumber) {
        boolean flag = false;
        for (String aa:orderNumber) {
            if (orderMapper.updateByLWOrderNo(aa)==1){
                flag = true;
            }else {
                flag = false;
            }
        }
        return flag;
    }

    @Override
    public boolean updatechuku(Order order) {
        boolean flag = false;
        if (orderMapper.updatechuku(order)>0){
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean updateruku(Order order) {
        boolean flag = false;
        if (orderMapper.updateruku(order)>0){
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean update(Order order) {
        boolean flag=false;
        if (orderMapper.update(order)>0){
            return true;
        }
        return flag;
    }

    @Override
    public List<Order> selectecharts(String finshtime) {
        return orderMapper.selectecharts(finshtime);
    }

    @Override
    public boolean updateByorderNumber(Order order) {
        boolean flag = false;
        if (orderMapper.updateByorderNumber(order)>0){
            flag = true;
        }
        return flag;
    }

    @Override
    public List<Order> getOrderAll(String orderNumber, Integer bookingid, Integer statusid, String exportorgname, Integer salesmanid, String customerName) {
        return orderMapper.getOrderAll(orderNumber, bookingid, statusid, exportorgname, salesmanid, customerName);
    }

    @Override
    public boolean getByspelnos(int spelno) {
        boolean flag = false;
        List<Integer> list = orderMapper.getByspelnos(spelno);
        for (Integer aa:list) {

            if (orderMapper.updateByspelnos(aa)==1){
                flag = true;
            }else {
                flag = false;
            }

        }
        return flag;
    }

    @Override
    public Order getByNewOrderNo(String orderNumber) {
        return orderMapper.getByNewOrderNo(orderNumber);
    }

    @Override
    public boolean updateByBookingno(Order record) {
        boolean flag = false;
        if (orderMapper.updateByBookingno(record)>0){
            flag = true;
        }
        return flag;
    }

//    @Override
//    public List<Order> orderCenter(Order order) {
//        return orderMapper.orderCenter(order);
//    }
}
